<template>
  <div>
<!--    <object>-->
<!--      <embed-->
<!--        id="rtmp-streamer"-->
<!--        src="../assets/RtmpStreamer.swf"-->
<!--        bgcolor="#000000"-->
<!--        quality="high"-->
<!--        width="750"-->
<!--        height="400"-->
<!--        allowScriptAccess="sameDomain"-->
<!--        type="application/x-shockwave-flash"/>-->
<!--    </object>-->
    <button @click="publish()" style="float: left"> 我要直播</button>
    <object wmode="transparent" id="rtmp-streamer" type="application/x-shockwave-flash" data="https://imgcache.qq.com/open/qcloud/video/act/live_web_push/RtmpStreamer.swf" style="width: 800px;height:800px">
      <param value="always" name="allowScriptAccess" />
      <param value="https://imgcache.qq.com/open/qcloud/video/act/live_web_push/RtmpStreamer.swf" name="movie" />
      <param value="high" name="quality" />
    </object>
  </div>
</template>

<script>
import Streamer from 'rtmp-streamer'
export default {
  name: 'PushLive',
  data () {
    return {
      Surl: 'rtmp://127.0.0.1:1935/live/',
      Sname: 'bbb',
      url: '',
      userList: [],
      isLive: 0,
      liveId: '',
      videoNum: 0,
      microphoneNum: 0
    }
  },
  mounted () {
    this.streamer = new Streamer(document.getElementById('rtmp-streamer'))
    navigator.mediaDevices.enumerateDevices().then(devices => {
      // 可以检测摄像头和麦克风数量
      devices.forEach(device => {
        if (device.kind === 'videoinput') this.videoNum++
        if (device.kind === 'audioinput') this.microphoneNum++
        console.log('videoinput' + this.videoNum)
        console.log('audioinput' + this.microphoneNum)
      })
    }).catch(function (err) {
      window.console.log(err.name + ': =======' + err.message)
    })
  },
  methods: {
    publish () {
      if (this.videoNum && this.microphoneNum) {
        this.streamer.publish(this.Surl, this.Sname)
        // this.streamer.play(msg.livePush, msg.safeUrl);
      } else if (!this.videoNum) {
        window.console.log('未检测到摄像头设备，无法直播!')
      } else {
        window.console.log('未检测到音频输入设备，无法直播!')
      }
    }
  }
}
</script>

<style scoped>

</style>
